using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;


namespace DataHelper.BLL
{
    public class Setting
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string Value { get; set; }
        public string Description { get; set; }
        public DateTime Updatedate { get; set; }

        #region SettingSelectAll
        public static List<Setting> SettingSelectAll(string strSearch="",int top = 1, int bottom = 20, SqlTransaction ConnectionString = null)
        {
            IDataReader dr = DataHelper.DAL.Setting.SettingSelectAll(strSearch,top,bottom,ConnectionString);
            List<Setting> SettingList = new List<Setting>();
            while(dr.Read())
            {
                Setting mySetting = new Setting
                {
                    ID = !dr.IsDBNull(dr.GetOrdinal("ID")) ? (int)dr["ID"] : 0,
                    Name = !dr.IsDBNull(dr.GetOrdinal("Name")) ? (string)dr["Name"] : null,
                    Value = !dr.IsDBNull(dr.GetOrdinal("Value")) ? (string)dr["Value"] : null,
                    Description = !dr.IsDBNull(dr.GetOrdinal("Description")) ? (string)dr["Description"] : null,
                    Updatedate = !dr.IsDBNull(dr.GetOrdinal("Updatedate")) ? (DateTime)dr["Updatedate"] : DateTime.Now
                };
                SettingList.Add(mySetting);
        }
        dr.Close();
        dr.Dispose();
        return SettingList;
        }
        #endregion
        #region SettingSelectRow
        public static Setting SettingSelectRow(int ID, SqlTransaction ConnectionString = null)
        {
            IDataReader dr = DataHelper.DAL.Setting.SettingSelectRow(ID, ConnectionString);
            Setting setting = null;

            if(dr.Read())
            {
                setting= new Setting
                {
                    ID = !dr.IsDBNull(dr.GetOrdinal("ID")) ? (int)dr["ID"] : 0,
                    Name = !dr.IsDBNull(dr.GetOrdinal("Name")) ? (string)dr["Name"] : null,
                    Value = !dr.IsDBNull(dr.GetOrdinal("Value")) ? (string)dr["Value"] : null,
                    Description = !dr.IsDBNull(dr.GetOrdinal("Description")) ? (string)dr["Description"] : null,
                    Updatedate = !dr.IsDBNull(dr.GetOrdinal("Updatedate")) ? (DateTime)dr["Updatedate"] : DateTime.Now,

                };
            }
        dr.Close();
        dr.Dispose();
        return setting;
        }
        #endregion
        #region SettingInsertRow
        public static void SettingInsertRow(int ID, string Name, string Value, string Description, DateTime Updatedate, SqlTransaction ConnectionString = null)
        {
            DataHelper.DAL.Setting.SettingInsertRow(ID, Name, Value, Description, Updatedate, ConnectionString);
        }
        #endregion
        #region SettingUpdateRow
        public static void SettingUpdateRow(int ID, string Name, string Value, string Description, DateTime Updatedate, SqlTransaction ConnectionString = null)
        {
            DataHelper.DAL.Setting.SettingUpdateRow(ID, Name, Value, Description, Updatedate, ConnectionString);
        }
        #endregion
        #region SettingDeleteRow
        public static void SettingDeleteRow(int ID, SqlTransaction ConnectionString = null)
        {
            DataHelper.DAL.Setting.SettingDeleteRow(ID,ConnectionString);
        }
        #endregion
    }
}
